package com.project.finance.product.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.finance.common.mapper.TbProductMapper;
import com.project.finance.common.po.TbProduct;
import com.project.finance.common.po.TbProductDetail;
import com.project.finance.common.vo.ResultMsg;
import com.project.finance.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private TbProductMapper productMapper;

    @Override
    public List<TbProduct> listTbProduct() {
        return productMapper.listTbProduct();
    }

    @Override
    public int insert(TbProduct tbProduct) {
        return productMapper.insert(tbProduct);
    }

    @Override
    public int update(TbProduct tbProduct) {
        return productMapper.updateByPrimaryKey(tbProduct);
    }

    @Override
    public int delete(List<Integer> productId) {
        return productMapper.listDelete(productId);
    }

    @Override
    public ResultMsg listTbProductByPage(int pageSize, int pageNum) {
        ResultMsg resultMsg = new ResultMsg();

        PageHelper.startPage(pageNum,pageSize);

        List<TbProduct> tbProducts = productMapper.listTbProduct();

        //获取结果集的分页信息
        PageInfo pageInfo = new PageInfo(tbProducts);
        // 获取总记录数
        long total = pageInfo.getTotal();
        resultMsg.setTatol(total);
        resultMsg.setData(tbProducts);
        return resultMsg;
    }
    //根据理财产品名称来查询一个理财产品信息
    @Override
    public List<TbProduct> getProoduct(String productdname) {
        Example example = new Example(TbProduct.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andLike("productName","%"+productdname+"%");
        List<TbProduct> tbProducts = productMapper.selectByExample(example);
        return tbProducts;
    }
}
